package com.ruoyi.ewem.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.ewem.domain.Record;
import com.ruoyi.ewem.service.RecordService;
import com.ruoyi.ewem.utils.MinioUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.List;

/**
 * @Author: Yanyanyu
 * @Date: 2024/7/28 19:16
 */
@CrossOrigin
@RestController
@RequestMapping("record")
public class RecordController extends BaseController {

    @Autowired
    private MinioUtils minioUtils;
    @Autowired
    private RecordService recordService;

    @RequestMapping("list/{productNum}")
    public TableDataInfo list(@PathVariable String productNum){
        List<Record> list = recordService.getList(productNum);
        return getDataTable(list);
    }

    @RequestMapping("addRecord")
    public AjaxResult addRecord(@RequestBody Record record){
        record.setCreateBy(SecurityUtils.getUsername());
        record.setCreateTime(new Date());
        boolean b = recordService.save(record);
        return toAjax(b);
    }

    @RequestMapping("upload")
    public String upload(MultipartFile file) throws Exception {
        return minioUtils.upload(file);
    }


}
